package com.hfjava.practice01;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @author Administrator
 * @version V1.0
 * @ProjectName:IntelliJ IDEA
 * @PackageName: com.hfjava.practice01.practice02.practice01
 * @ClassName: InputWrite
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @date 2019/12/24 9:20
 * @Copyright 大牛版板所有
 */
public class InputWrite {
    public static void main(String[] args)throws IOException {
        FileOutputStream files = null;
        try {
            files = new FileOutputStream("chapter03\\doc\\test.txt",true);
            String str = "Hello World";
            byte[] words = str.getBytes();
            files.write(words,0,words.length);
            System.out.println("Test文件已更新！");
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try {
                files.close();
            }catch (Exception e){
                e.printStackTrace();
            }
        }

        FileInputStream file = null;
        try {
            file = new FileInputStream("chapter03\\doc\\test.txt");
            int data;
            while ((data = file.read()) != -1 ){
                System.out.print((char) data);
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try {
                file.close();
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
}
